//***************************************************************************
//
//  File........: sound.c
//
//  Author(s)...: ATMEL Norway
//
//  Target(s)...: ATmega169
//
//  Compiler....: GCC 4.1.1; avr-libc 1.4.5
//
//  Description.: AVR Butterfly sound routines
//
//  Revisions...: 1.0
//
//  YYYYMMDD - VER. - COMMENT                                       - SIGN.
//
//  20030116 - 1.0  - Created                                       - LHM
//  20031009          port to gcc/avr-libc                          - M.Thomas
//  20040123          added temp.-var.                              - n.n./mt
//  20050727          added local helper-function                   - mt
//  20060107          fixed or in pause-if                          - mt
//  20070605          added song                                    - mt
//
//***************************************************************************


#include <projectdefinitions.h>


/*****************************************************************************/

int vol2;

void Sound_Init(int f, float t )
{
    int icr1;
	TCCR1A = (1<<COM1A1);// | (1<<COM1A0); // Set OC1A when upcounting, clear when downcounting
    TCCR1B = (1<<WGM13);        // Phase/Freq-correct PWM, top value = ICR1
   
                    
    
   	OCR1AH = 0;        // Set a initial value in the OCR1A-register
    OCR1AL = vol2; 

	icr1=1000000/(2*f);
	ICR1=icr1;
	
	SET_BIT(TCCR1B, CS10)		// start Timer1, prescaler(1) 
	
	WAIT_SEC(t)
	
	CLEAR_BIT(TCCR1B, CS10)		// clear Timer1, prescaler(1) 
	
	//DDRB  &= 0b11011111;

}

void Volumen(int vol){
	
		vol2=vol;

        OCR1AH = 0;
		OCR1AL = vol;
}

